package packge

import (
	"awesomeTask/application/client"
	"awesomeTask/application/models/programe"
	"awesomeTask/application/variable"
	awesomeTask "awesomeTask/commom"
)

const TABLE_NAME = "t_project_packge"

func GetPackge(projectId string) []map[string]interface{} {
	return awesomeTask.Query("select * from "+TABLE_NAME+" where project_id=?", projectId)
}
func EditOrInsert(params map[string]interface{}) bool {
	insertParams := map[string]interface{}{
		"project_id":  params["project_id"],
		"id":          params["id"],
		"packge":      params["packge"],
		"version":     params["version"],
		"update_time": awesomeTask.Now(),
	}
	if params["id"] == nil || params["id"] == "" {
		insertParams["create_time"] = awesomeTask.Now()
	}
	eventParams := map[string]interface{}{
		"package":     params["packge"],
		"projectPath": programe.GetprojectNameByProjectId(params["project_id"].(string)),
	}
	client.SendEventToAll(variable.ON_INSTALL_PACKAGE, eventParams)
	return awesomeTask.InsertOrUpdate(TABLE_NAME, insertParams)
}
